# -*- coding: utf-8 -*-
from Tkinter import *
import tkMessageBox as MsgBox

#from BaseDonnees import *
 
#import os
#os.environ['PATH'] ="C:/Oracle/Client/bin" + os.pathsep +os.environ['PATH'] 
#import cx_Oracle
class VueInitialisation(Frame):
    def __init__(self,master,parent,**cnf):
        KeysList=cnf.keys()
        self.parent = parent
        self.master=master
        Frame.__init__(self,master,cnf)              
        self.pack(side=LEFT,anchor=NW)
        self.l1=Listbox(self)
        self.l1.grid(row=0, column=0)
        self.l1.insert(END, "Emp")
        self.l1.insert(END, "Dept")
        self.l1.insert(END, "Client")
        self.l1.insert(END, "Inventaire")
        self.l1.insert(END, "Produit")
        self.l1.insert(END, "Commande")
        self.l1.insert(END, "Item")
        self.l1.insert(END, "Region")
        self.l1.insert(END, "Poste")
        self.l1.insert(END, "Depot")
        self.l2=Listbox(self)
        
        self.l2.grid(row=0, column=2)
        self.center=Frame(self)
        self.B=Button(self.center, text=">", command=self.insertElement)
        self.B1=Button(self.center, text="<", command=self.deleteElement)
        self.bouton= Button(self,text="Creer", command=self.choixTables)
        self.bouton.grid(row=1, column=2)
        self.B.pack()
        self.B1.pack()
        self.center.grid(row=0, column=1)
        #self.center.pack()
        
        #self.BaseDonnees= CommunicationBaseDonnees()
        #self.BaseDonnees.DemarrerConnection("b52equip1", "var2", "titan")
        
    def choixTables(self):
        #listeNomsTables=self.parent.BaseDonnees.ObtenirEnregistrement(self,  "Nom", "TablesStandards")
      
        for i in range(self.l2.size()):      
            self.Table = self.l2.get(i)
            Reponse = self.creerTable()
            if (Reponse[0]==0):
                MsgBox.showerror('PERP | Création des tables','Une erreur c\'est produite'+\
                                    Reponse[1])
            else:               
                reponse= self.parent.serveur.ExecuterRequeteSQL(Reponse[1][0][0])
                if (Reponse[0]==0):
                    MsgBox.showerror('PERP | Création des tables','Une erreur c\'est produite'+\
                                        Reponse[1])
                else:
                    MsgBox.showinfo('PERP | Création des tables','La table '+\
                                                self.Table+' a été crée avec succès')
                
    def insertElement(self):
        selection=self.l1.curselection()
        self.l2.insert(END, self.l1.get(selection[0]))
        self.l1.delete(selection)
        pass
    
    def deleteElement(self):
        delete=self.l2.curselection()
        self.l1.insert(END, self.l2.get(delete[0]))
        self.l2.delete(delete)
        pass
    
    def creerTable(self):
        Requete= "select Requete from tablesstandards where lower(Nom)='"+ self.Table.lower()+"'"
        reponse= self.parent.serveur.ExecuterRequeteSQLWhere(Requete)
        return reponse

        
if __name__ == '__main__':
    root=Tk()
    root.geometry('400x300')
    vi=VueInitialisation(root,None)
    root.mainloop()
    
         